@{ViewBag.Title = " Persona "; Layout = "../Shared/_LayoutJtable.cshtml";}
<div class="filtering"><form>
    <label>Apellido Paterno: <input type="text" name="apellidoPaterno" id="apellidoPaterno" /></label>
    <label>Apellido Materno: <input type="text" name="apellidoMaterno" id="apellidoMaterno" /></label>
    <label>Nombre: <input type="text" name="nombres" id="nombres" /></label>
<button type="submit" id="LoadRecordsButton" class="button medium orange" >Buscar Coincidencias</button>
</form></div>
<div id="MyTableContainer"></div>
<script type="text/javascript">
     $(document).ready(function () {
     $('#MyTableContainer').jtable({
         title: 'Persona',
         paging: true,
         pageSize: 40,
         sorting: true,
         defaultSorting: 'Id ASC',
         actions: {
             listAction: '@Url.Action("JSONDataPagerSearch")'
         },
         fields:
         {
          Id: {
                 key: true,
                 create: false,
                 edit: false,
                 list: false
              }
              ,
              Guid:
              {
                type: 'hidden'
              }
             ,
              Codigo: {                 
                 title:'Codigo',
                 create: true,
                 edit: true,
                 list: true,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             CI: {
                 title:'CI',
                 create: true,
                 edit: true,
                 list: true,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             CIMilitar: {
                 title:'CIMilitar',
                 create: true,
                 edit: true,
                 list: true,
                 inputClass: 'validate[required]',
                 sorting: false
             }
             ,
             ApellidoPaterno: {
                 title:'Apellidos Paterno',
                 create: true,
                 edit: true,
                 list: true,
                 sorting: false
             }
             ,
             ApellidoMaterno: {
                 title:'Apellido Materno',
                 create: true,
                 edit: true,
                 list: true,
                 sorting: false
             }
             ,
             Nombre1: {
                 title:'Nombre',
                 create: true,
                 edit: true,
                 list: true,
                 sorting: false
             }
             ,             
             Dataform:
             {
                 title: 'Actualizar',
                 width: '10px',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (tempData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../Content/images/comment.png" title="Actualizar Datos" />');
                     $img.click(function () {
                         //window.open('../Reporte/FilePersonal?PersonaId=' + tempData.record.Id);
                         location.href = '../Persona/IrADataForm?PersonaId=' + tempData.record.Id;
                     });

                     return $img;
                 }
             },             
             Arma: {
                 title: 'Arma',
                 width: '10px',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (personData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../Content/images/comment.png" title="Arma" />');
                     //Open child table when user clicks the image
                     $img.click(function () {
                         $('#MyTableContainer').jtable('openChildTable',
                                    $img.closest('tr'),
                                    {
                                        title: 'HISTORIAL DE ESPECIALIDADES DE : ' + personData.record.NombreCompleto,
                                        actions: {
                                            listAction: '@Url.Action("../PersonaArma/GetPorPersonaGuid")?guid=' + personData.record.Guid,
                                            deleteAction: '@Url.Action("../PersonaArma/JSONDelete")',
                                            updateAction: '@Url.Action("../PersonaArma/JSONUpdate")',
                                            createAction: '@Url.Action("../PersonaArma/JSONCreate")'
                                        },
                                        fields: {

                                            Id: {
                                                key: true,
                                                create: false,
                                                edit: false,
                                                list: false
                                            },

                                            PersonaId_FK: {
                                                type: 'hidden',
                                                defaultValue: personData.record.Id
                                            },
                                            EsActual: {
                                                title: 'EsActual',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                type: 'checkbox',
                                                values: { 'false': 'Desactivado', 'true': 'Activado' },
                                                sorting: false
                                            }
                                            ,
                                            MotivoActualizacion: {
                                                title: 'MotivoActualizacion',
                                                type: 'textarea',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                sorting: false
                                            }
                                            ,
                                            Descripcion: {
                                                title: 'Descripcion',
                                                type: 'textarea',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                sorting: false
                                            }                                            
                                            ,
                                            ArmaId_FK: {
                                                title: 'Arma',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                options: '@Url.Action("../Arma/JSONGetElementsForDropDownList")'
                                            }

                                        }
                                    }, function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    });
                     });
                     //Return image to show on the person row
                     return $img;
                 }
             },

             Grado: {
                 title: 'Grado',
                 width: '10px',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (personData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../Content/images/comment.png" title="Grado" />');
                     //Open child table when user clicks the image
                     $img.click(function () {
                         $('#MyTableContainer').jtable('openChildTable',
                                    $img.closest('tr'),
                                    {
                                        title: 'HISTORIAL ASCENSO DE : ' + personData.record.NombreCompleto,
                                        actions: {
                                            listAction: '@Url.Action("../HistorialAscenso/GetPorPersonaGuid")?guid=' + personData.record.Guid,
                                            deleteAction: '@Url.Action("../HistorialAscenso/JSONDelete")',
                                            updateAction: '@Url.Action("../HistorialAscenso/JSONUpdate")',
                                            createAction: '@Url.Action("../HistorialAscenso/JSONCreate")'
                                        },
                                        fields: {
                                            PersonaId_FK: {
                                                type: 'hidden',
                                                defaultValue: personData.record.Id
                                            },
                                            Guid: {
                                                type: 'hidden'
                                            }
                                            ,
                                            FechaAscenso: {
                                                title: 'FechaAscenso',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                type: 'date',
                                                displayFormat: 'dd/mm/yy',
                                                inputClass: 'validate[required]',
                                                sorting: false
                                            }
                                            ,
                                            FechaRegistro: {
                                                title: 'FechaRegistro',
                                                create: false,
                                                edit: false,
                                                list: true,
                                                type: 'date',
                                                displayFormat: 'dd/mm/yy',
                                                inputClass: 'validate[required]',
                                                sorting: false
                                            }
                                            ,
                                            Descripcion: {
                                                title: 'Descripcion',
                                                type: 'textarea',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                sorting: false
                                            }
                                            ,
                                            Motivo: {
                                                title: 'Motivo',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                sorting: false
                                            }
                                            ,
                                            NumAntiguedad: {
                                                title: 'NumAntiguedad',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                inputClass: 'validate[required]',
                                                sorting: false
                                            }
                                            ,
                                            GradoId_FK: {
                                                title: 'Grado',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                options: '@Url.Action("../Grado/JSONGetElementsForDropDownList")'
                                            },
                                            Documento:
                                             {
                                                 title: 'Doc',
                                                 width: '50px',
                                                 sorting: false,
                                                 edit: false,
                                                 create: false,
                                                 listClass: 'child-opener-image-column',
                                                 display: function (tempData) {
                                                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../Content/images/comment.png" title="Documento Escaneado" />');
                                                     $img.click(function () {
                                                         //window.open('../Media/Cargar?guid=' + tempData.record.Guid);
                                                         location.href = '../Media/Cargar?guid=' + personData.record.Guid + '&titulo=GRADO de ' + personData.record.NombreCompleto
                                                     });

                                                     return $img;
                                                 }
                                             }

                                        }
                                    }, function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    });
                     });
                     //Return image to show on the person row
                     return $img;
                 }
             },



             Especialidades: {
                 title: 'Esp.',
                 width: '10px',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (personData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../Content/images/comment.png" title="Grado" />');
                     //Open child table when user clicks the image
                     $img.click(function () {
                         $('#MyTableContainer').jtable('openChildTable',
                                    $img.closest('tr'),
                                    {
                                        title: 'HISTORIAL DE ESPECIALIDADES DE : ' + personData.record.NombreCompleto,
                                        actions: {
                                            listAction: '@Url.Action("../HistorialEspecialidad/GetPorPersonaGuid")?guid=' + personData.record.Guid,
                                            deleteAction: '@Url.Action("../HistorialEspecialidad/JSONDelete")',
                                            updateAction: '@Url.Action("../HistorialEspecialidad/JSONUpdate")',
                                            createAction: '@Url.Action("../HistorialEspecialidad/JSONCreate")'
                                        },
                                        fields: {
                                            PersonaId_FK: {
                                                type: 'hidden',
                                                defaultValue: personData.record.Id
                                            },
                                            Guid: {
                                                type: 'hidden'
                                            }
                                            ,
                                            FechaDesde: {
                                                title: 'FechaDesde',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                type: 'date',
                                                displayFormat: 'dd/mm/yy',
                                                inputClass: 'validate[required]',
                                                sorting: false
                                            }
                                            ,
                                            FechaHasta: {
                                                title: 'FechaHasta',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                type: 'date',
                                                displayFormat: 'dd/mm/yy',
                                                inputClass: 'validate[required]',
                                                sorting: false
                                            }   
                                            ,
                                            Descripcion: {
                                                title: 'Descripcion',
                                                type: 'textarea',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                sorting: false
                                            }
                                            ,
                                            EspecialidadId_FK: {
                                                title: 'Especialidad',
                                                create: true,
                                                edit: true,
                                                list: true,
                                                options: '@Url.Action("../Especialidad/JSONGetElementsForDropDownList")'
                                            }
                                            ,
                                            Documento:
                                            {
                                                title: 'Doc',
                                                width: '50px',
                                                sorting: false,
                                                edit: false,
                                                create: false,
                                                listClass: 'child-opener-image-column',
                                                display: function (tempData) {
                                                    var $img = $('<img class="child-opener-image" with="20" height="20" src="../Content/images/comment.png" title="Documento Escaneado" />');
                                                    $img.click(function () {
                                                        //window.open('../Media/Cargar?guid=' + tempData.record.Guid);
                                                        location.href = '../Media/Cargar?guid=' + personData.record.Guid + '&titulo=GRADO de ' + personData.record.NombreCompleto
                                                    });

                                                    return $img;
                                                }
                                            }

                                        }
                                    }, function (data) { //opened handler
                                        data.childTable.jtable('load');
                                    });
                     });
                     //Return image to show on the person row
                     return $img;
                 }
              },
             Ficha:
           {
               title: 'Ficha',
               width: '10px',
               sorting: false,
               edit: false,
               create: false,
               listClass: 'child-opener-image-column',
               display: function (tempData) {
                   var $img = $('<img class="child-opener-image" with="20" height="20" src="../Content/images/comment.png" title="Ficha Personal" />');
                   $img.click(function () {
                       window.open('../Reporte/FilePersonal?PersonaId=' + tempData.record.Id);                       
                   });

                   return $img;
               }
           },
             EnviarEmail:
             {
                 title: 'EMail',
                 width: '10px',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (tempData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../Content/images/comment.png" title="Email" />');
                     $img.click(function () {
                         //window.open('../Persona/EnviarEmail?guid=' + tempData.record.Guid);
                         location.href = '../Persona/EnviarEmail?guid=' + tempData.record.Guid;
                     });

                     return $img;
                 }
             },
             Foto:
             {
                 title: 'Foto',
                 width: '10px',
                 sorting: false,
                 edit: false,
                 create: false,
                 listClass: 'child-opener-image-column',
                 display: function (tempData) {
                     var $img = $('<img class="child-opener-image" with="20" height="20" src="../Content/images/comment.png" title="Email" />');
                     $img.click(function () {
                         //window.open('../Media/Cargar?guid=' + tempData.record.Guid);
                         location.href = '../Media/Cargar?guid=' + tempData.record.Guid + '&titulo=' + tempData.record.ApellidoPaterno + ' ' + tempData.record.ApellidoMaterno + ' ' + tempData.record.Nombre1;
                     });

                     return $img;
                 }
             }




},
formCreated: function (event, data) {data.form.validationEngine();},
formSubmitting: function (event, data) {return data.form.validationEngine('validate');},
formClosed: function (event, data) { data.form.validationEngine('hide'); data.form.validationEngine('detach'); }
});
$('#LoadRecordsButton').click(function (e) { e.preventDefault(); $('#MyTableContainer').jtable('load', { nombres: $('#nombres').val(), apellidoPaterno: $('#apellidoPaterno').val(), apellidoMaterno: $('#apellidoMaterno').val() }); });
$('#LoadRecordsButton').click();
});
</script>

